package sn.gandal.mobile.kalpet.utils;

import java.io.IOException;
import java.io.StringWriter;
import java.io.Writer;
import java.util.Calendar;
import java.util.Date;

import org.codehaus.jackson.JsonGenerationException;
import org.codehaus.jackson.map.JsonMappingException;
import org.codehaus.jackson.map.ObjectMapper;
import org.codehaus.jackson.map.SerializationConfig;

import sn.gandal.mobile.kalpet.R;
import sn.gandal.mobile.kalpet.data.entities.Account;
import android.text.format.DateFormat;
import android.widget.EditText;
import android.widget.RadioButton;

public class Java2JsonParser {

	/**
	 * 
	 * @param ob 
	 * @return transforme un object respectant les spec Pojo en json
	 * @throws JsonGenerationException
	 * @throws JsonMappingException
	 * @throws IOException
	 */
	public static String parseObject2Json(Object ob) throws JsonGenerationException, JsonMappingException, IOException{

		ObjectMapper mapper = new ObjectMapper();
		mapper.configure(SerializationConfig.Feature.WRAP_ROOT_VALUE, false);
		Writer strWriter = new StringWriter();
		mapper.writeValue(strWriter, ob);
		String json = strWriter.toString();

		return json;
	}	
	public static String parseList2Json(Object ob, Object type) throws JsonGenerationException, JsonMappingException, IOException{

		ObjectMapper mapper = new ObjectMapper();
		mapper.configure(SerializationConfig.Feature.WRAP_ROOT_VALUE, true);
		Writer strWriter = new StringWriter();
		mapper.writeValue(strWriter, type);
		String json = strWriter.toString();

		return json;
	}	
}
